<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>年排产（此功能去掉了）</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<style type="text/css">
		 .left-label {
		 	width: 120px !important
		 }
	</style>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
    <div class="layui-inline">
    	<input class="layui-input" name="searchTime" id="searchTime" placeholder="请选择时间" style="display: inline; width: 80%">
    </div>
    <button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">  搜索</i></button>
</div>

<table class="layui-hide" id="tableList" lay-filter="tableList"></table>
<table class="layui-hide" id="detail" lay-filter="detail"></table>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="add"><i class="layui-icon layui-icon-add-1">  新增</i></button>
		<button class="layui-btn layui-btn-blue" lay-event="delete"><i class="layui-icon layui-icon-delete">批量删除</i></button>
	</div>
</script>
 
<script type="text/html" id="rowToolbar">
	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
              
          
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
 
<script type="text/javascript">
	layui.use(['table','layer','upload','form','laydate'], function(){
		var table = layui.table;
		var layer = layui.layer;
		var laydate = layui.laydate;
	    var form = layui.form;
		
		var $ = layui.jquery, active = {
			reload:function () {
				var searchTime = $("#searchTime").val();
				console.log(searchTime)
				table.reload('contenttable',{
					method:'get',
					where:{"years":searchTime}
				});
			}
		}
		$('.layui-btn').on('click', function(){
	        var type = $(this).data('type');
	        active[type] ? active[type].call(this) : '';
	    });
		table.render({
		    elem: '#tableList'
		    ,url:'${pageContext.request.contextPath }/year/yearList.do'
		    ,toolbar: '#toolbar'
		    ,title: '滚动排产单'
		    ,id :'contenttable'
		    ,limits:[10,20,30]
		    ,cols: [[
		      {type: 'checkbox', fixed: 'left'},
		      {field:'id', title:'ID' },
		      {field:'years', title:'年份', fixed: 'left', unresize: true, sort: true},
		      {field:'maker', title:'编制'},
		      {field:'approval', title:'审核'},
		      {field:'adate', title:'日期'},
		      {field:'jcheck', title:'技术部查收'},
		      {field:'jdate', title:'日期'},
		      {field:'zcheck', title:'综合部查收'},
		      {field:'zdate', title:'日期'},
		      {fixed:'right', title:'操作', toolbar: '#rowToolbar'}
		    ]],
		    page: true,
		    done: function () {
		        $("[data-field='id']").css('display','none');
		    }
		});
		
		table.render({
		    elem: '#detail'
		    ,url:'${pageContext.request.contextPath }/year/yearDetailList.do'
		    ,title: '年生产排产详情'
		    ,id :'contenttable2'
		    ,limits:[10,20,30]
		    ,cols: [[
		      {type: 'checkbox', fixed: 'left'},
		      ,{field:'sub', title:'组件编码（支）' , width:139}
		      ,{field:'jan', title:'1月', edit: 'text'}
		      ,{field:'feb', title:'2月', edit: 'text'}
		      ,{field:'mar', title:'3月', edit: 'text'}
		      ,{field:'apr', title:'4月', edit: 'text'}
		      ,{field:'may', title:'5月', edit: 'text'}
		      ,{field:'jun', title:'6月', edit: 'text'}
		      ,{field:'jul', title:'7月', edit: 'text'}
		      ,{field:'aug', title:'8月', edit: 'text'}
		      ,{field:'sept', title:'9月', edit: 'text'}
		      ,{field:'oct', title:'10月', edit: 'text'}
		      ,{field:'nov', title:'11月', edit: 'text'}
		      ,{field:'dec', title:'12月', edit: 'text'}
		    ]],
		    page: true
		});
	  
		
		 //监听行单击事件（单击事件为：rowDouble）
		  table.on('row(tableList)', function(obj){
		    var data = obj.data;
			table.reload('contenttable2',{
				method:'get',
				where:{"remark":data.years}
			});
		  });
		
		//头工具栏事件
		table.on('toolbar(tableList)', function(obj){
			var checkStatus = table.checkStatus(obj.config.id);
		    switch(obj.event){
		    	case 'add':
			    	layer.open({
						type: 1 					//Page层类型
				  		,area: ['550px', '650px'] 	//宽  高
				  		,title: '新增'
				  		,shade: 0.6 				//遮罩透明度
				  		,maxmin: true 				//允许全屏最小化
				  		,anim: 1 					//0-6的动画形式，-1不开启
				  		,content: window.location.href="/year/toCreate.do"
					}); 
		      	break;
		    	case 'delete':
		        	var data = checkStatus.data;
		        	if(data.length==0){
		        		toastr.warning("请至少选择一条记录！");
		        	}else {
		        		var ids = "";
			        	for(var i=0;i<data.length;i++){
			        		 if(i != data.length-1) {
				        	 	ids +=data[i].id+",";
				        	 }else {
				        	 	ids +=data[i].id;
				        	 }
			        	}
			        	layer.confirm('确定删除吗？', function(index){
					        $.ajax({
						    	type:'post',
						    	url:'${pageContext.request.contextPath }/year/deleteYear.do',
						    	data:{"ids":ids},
						    	success:function(data){
						    		if(data > 0){
						    			toastr.success("删除成功！");
						    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
											window.location.reload();  
										},2000);
						    		}else{
						    			toastr.warning("删除失败！");
						    		}
						    	}
						    })
			        	})
		        	}
		      	break;
		      	case 'select':
		      		console.log(obj)
		      	break;
		    };
		});
	  
		//监听行工具事件
		table.on('tool(tableList)', function(obj){
			var data = obj.data;
			console.log(obj)
			if(obj.event === 'del'){
			  layer.confirm('确定删除吗？', function(index){
			    var id = obj.data.id;
			    $.ajax({
			    	type:'post',
			    	url:'${pageContext.request.contextPath }/year/deleteYear.do',
			    	data:{"ids":id},
			    	success:function(data){
			    		if(data > 0){
			    			toastr.success("删除成功！");
			    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
								window.location.reload();  
							},2000);
			    		}else{
			    			toastr.warning("删除失败！");
			    		}
			    	}
			    })
			    layer.close(index);
			  });
			} else if(obj.event === 'edit'){
				layer.open({
				  type: 1 					//Page层类型
				  ,area: ['550px', '450px'] //宽  高
				  ,title: '编辑'
				  ,shade: 0.6 				//遮罩透明度
				  ,maxmin: true 			//允许全屏最小化
				  ,anim: 1 					//0-6的动画形式，-1不开启
				  ,content: '<form class="layui-form" id="editFormID">'+
				  	'<input type="hidden" id="id" name="id" value="'+data.id+'" lay-verify="id" >'+
					'<label class="layui-form-label left-label">编制</label><input class="layui-input" id="maker" name="maker" value="'+data.maker+'" lay-verify="maker" style="width:300px; margin-top:15px"><br>'+
					'<label class="layui-form-label left-label">审核</label><input class="layui-input" id="approval" name="approval" value="'+data.approval+'" lay-verify="approval" style="width:300px"><br>'+
					'<label class="layui-form-label left-label">技术部查收</label><input class="layui-input" id="jcheck" name="jcheck" value="'+data.jcheck+'" lay-verify="jcheck" style="width:300px"><br>'+
					'<label class="layui-form-label left-label">综合部查收</label><input class="layui-input" id="zcheck" name="zcheck" value="'+data.zcheck+'" lay-verify="zcheck" style="width:300px"><br>'+
					'<button class="layui-btn layui-btn-blue" lay-submit lay-filter="editForm" style="margin-left:160px; margin-bottom: 20px">立即提交</button>&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px">重置</button>'+
				'</form>'
				,success: function(){
					//出厂日期
					laydate.render({
					    elem: '#outTime2',
					    format: 'yyyy-MM-dd HH:mm:ss'
					  });
					//购买日期
					laydate.render({
					    elem: '#buyTime2',
					    format: 'yyyy-MM-dd HH:mm:ss'
					 });
				}
				});
			}
		});
		
		 //监听单元格编辑    详情修改
		  table.on('edit(detail)', function(obj){
		    var value = obj.value //得到修改后的值
		    ,data = obj.data //得到所在行所有键值
		    ,field = obj.field; //得到字段
		    //layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
		    $.ajax({
		    	type:'post',
		    	url:'${pageContext.request.contextPath }/year/createDetail.do',
		    	data: ""+field+"=" + value + "&sub=" + data.sub,
		    	success:function(data){
		    		if(data>0){
		    			toastr.success("修改成功！");
		    		}else{
		    			toastr.warning("修改失败！");
		    		}
		    	}
		    })
		  });
		
	    /**
	     * 通用表单提交(AJAX方式)（修改）
	     */
	    form.on('submit(editForm)', function (data) {
	    	$.ajax({
				url : '${pageContext.request.contextPath}/year/editYear.do',
				data: data.field,
				data : new FormData($('#editFormID')[0]),
				cache : false,
				type : "post",
				dataType : "json",
				processData : false,
				contentType : false,
				}).done(
					function(res) {
						if (res == 1) {
							toastr.success('修改成功！');
							setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
								window.location.reload();  
							},2000);
						}
					}
				).fail(
					function(res) {
						toastr.error('修改失败！');
					}
				)
				return false;
	    });
	  	//时间检索
	    laydate.render({
	      elem: '#searchTime',
	      format: 'yyyy'
	    });
	});
	toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
</script>

</body>
</html>